package com.example.pickupclosefirstdemo.fragmentinterflowactivity;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.pickupclosefirstdemo.R;
import com.example.pickupclosefirstdemo.base.BaseActivity;
import com.example.pickupclosefirstdemo.databinding.ActivityInterflowBinding;
import com.example.pickupclosefirstdemo.fragment.BaseFragmentAdapter;
import com.example.pickupclosefirstdemo.fragment.interflowfirstfragment.InterflowFirstFragment;
import com.example.pickupclosefirstdemo.fragment.InterflowSecondFragment;
import com.example.pickupclosefirstdemo.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

import static com.example.pickupclosefirstdemo.bean.Constants.AROUTER_ACT_TO_INTERFLOWACTIVITY;

@Route(path = AROUTER_ACT_TO_INTERFLOWACTIVITY)
public class InterflowActivity extends BaseActivity<ActivityInterflowBinding> implements ViewPager.OnPageChangeListener {

    List<Fragment> fragments = new ArrayList<>();

    @Autowired
    public String key;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_interflow;
    }

    @Override
    public void initView() {
        binding.setActivity(this);
    }

    @Override
    public void initData() {
        fragments.add(new InterflowFirstFragment());
        fragments.add(new InterflowSecondFragment());
        BaseFragmentAdapter fragmentAdapter = new BaseFragmentAdapter(getSupportFragmentManager());
        fragmentAdapter.addData(fragments);
        if (binding != null) {
            LogUtil.e("interflowActivity接收到-->" + key);
            try {
                binding.vpModule.setAdapter(fragmentAdapter);
                binding.vpModule.setCurrentItem(0);
                binding.vpModule.addOnPageChangeListener(this);
            } catch (Exception e) {
                LogUtil.e("报错");
            }
        }else{
            LogUtil.e("bundel == null");
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                binding.vpModule.setCurrentItem(0);
                break;
            case 1:
                binding.vpModule.setCurrentItem(1);
                break;
            default:
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    public void getActStr(String str) {
        LogUtil.e("调用-->"+ str);
        binding.tvModuleTop.setText(str);
    }
}
